//
//  PostContentCell.m
//  CKApp
//
//  Created by CC on 2020/9/12.
//  Copyright © 2020 This Moment. All rights reserved.
//

#import "PostContentCell.h"
#import "LcFoundation.h"
#import "PostContentCellData.h"

@interface PostContentCell () <LimitInputTextViewDelegate>
@property(nonatomic, weak) IBOutlet UIView* container;
@end

@implementation PostContentCell

- (void)postContruct {
  [super postContruct];
  self.container.layer.cornerRadius = 10.0;
  self.container.backgroundColor = LC_COLOR_INPUT_BACKGROUND;

  [self.textView setLcFont:[LcFont dr14]];
  [self.countLabel setLcFont:[LcFont dr10].fontColor([UIColor colorWithHexString:@"c0c0c3"])];

  self.textView.limitInputDelegate = self;

  self.countLabel.text = @"0/1000";
}

- (CGFloat)height {
  return 160.0;;
}

#pragma mark - LimitInputTextViewDelegate
- (void)textDidChangeAction:(LimitInputTextView *)textView {
  self.countLabel.text = [NSString stringWithFormat:@"%zd/1000", self.textView.text.length];
}

- (void)textDidEndEditingAction:(LimitInputTextView *)textView {
  PostContentCellData* cellData = (PostContentCellData*)self.cellData;
  cellData.text = textView.text;
  if (cellData.doneClickHandler != nil) {
    cellData.doneClickHandler(cellData);
  }
}

@end
